﻿// Autore: Alessio Parma

using System;
using System.Diagnostics;
using RecipesManager.Data.Operations.Properties;

namespace RecipesManager.Data.Operations
{
    static class Utils
    {
        static readonly int[] CategoryRatings = new int[5];
        static readonly int[] GuestRatings = new int[5];
        static readonly int[] IngredientRatings = new int[5];
        static readonly int[] RecipeRatings = new int[5];

        static Utils()
        {
            RecipeRatings[(int) FoodRating.VeryBad] = Settings.Default.VeryBadRecipeRating;
            RecipeRatings[(int) FoodRating.Bad] = Settings.Default.BadRecipeRating;
            RecipeRatings[(int) FoodRating.Neuter] = Settings.Default.NeuterRecipeRating;
            RecipeRatings[(int) FoodRating.Good] = Settings.Default.GoodRecipeRating;
            RecipeRatings[(int) FoodRating.VeryGood] = Settings.Default.VeryGoodRecipeRating;

            GuestRatings[(int) GuestRating.VeryBad] = Settings.Default.VeryBadGuestRating;
            GuestRatings[(int) GuestRating.Bad] = Settings.Default.BadGuestRating;
            GuestRatings[(int) GuestRating.Neuter] = Settings.Default.NeuterGuestRating;
            GuestRatings[(int) GuestRating.Good] = Settings.Default.GoodGuestRating;
            GuestRatings[(int) GuestRating.VeryGood] = Settings.Default.VeryGoodGuestRating;

            CategoryRatings[(int) FoodRating.VeryBad] = Settings.Default.VeryBadCategoryRating;
            CategoryRatings[(int) FoodRating.Bad] = Settings.Default.BadCategoryRating;
            CategoryRatings[(int) FoodRating.Neuter] = Settings.Default.NeuterCategoryRating;
            CategoryRatings[(int) FoodRating.Good] = Settings.Default.GoodCategoryRating;
            CategoryRatings[(int) FoodRating.VeryGood] = Settings.Default.VeryGoodCategoryRating;

            IngredientRatings[(int) FoodRating.VeryBad] = Settings.Default.VeryBadIngredientRating;
            IngredientRatings[(int) FoodRating.Bad] = Settings.Default.BadIngredientRating;
            IngredientRatings[(int) FoodRating.Neuter] = Settings.Default.NeuterIngredientRating;
            IngredientRatings[(int) FoodRating.Good] = Settings.Default.GoodIngredientRating;
            IngredientRatings[(int) FoodRating.VeryGood] = Settings.Default.VeryGoodIngredientRating;
        }

        public static int CategoryRatingToInt(FoodRating rating)
        {
            return CategoryRatings[(int) rating];
        }

        public static int GuestRatingToInt(GuestRating rating)
        {
            return GuestRatings[(int) rating];
        }

        public static int IngredientRatingToInt(FoodRating rating)
        {
            return IngredientRatings[(int) rating];
        }

        public static int RecipeRatingToInt(FoodRating rating)
        {
            return RecipeRatings[(int) rating];
        }

        public static GuestType GuestTypeForScore(int score)
        {
            return (score > 0) ? GuestType.Recommended : (score < 0) ? GuestType.NotRecommended : GuestType.Common;
        }

        public static RecipeType RecipeTypeForScore(int score)
        {
            return (score > 0) ? RecipeType.Recommended : (score < 0) ? RecipeType.NotRecommended : RecipeType.Common;
        }
    }

    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
    [Conditional("CONTRACTS_FULL")]
    sealed class ContractAbbreviatorAttribute : Attribute
    {
    }
}